package com.haoniu.premises.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoniu.common.log.annotation.Log;
import com.haoniu.common.log.enums.BusinessType;
import com.haoniu.common.security.annotation.RequiresPermissions;
import com.haoniu.premises.domain.TbPremisesInfo;
import com.haoniu.premises.service.ITbPremisesInfoService;
import com.haoniu.common.core.web.controller.BaseController;
import com.haoniu.common.core.web.domain.AjaxResult;
import com.haoniu.common.core.utils.poi.ExcelUtil;
import com.haoniu.common.core.web.page.TableDataInfo;

/**
 * 楼盘信息Controller
 * 
 * @author haoniu
 * @date 2022-07-15
 */
@RestController
@RequestMapping("/info")
public class TbPremisesInfoController extends BaseController
{
    @Autowired
    private ITbPremisesInfoService tbPremisesInfoService;

    /**
     * 查询楼盘信息列表
     */
    @RequiresPermissions("haoniu-premises:info:list")
    @GetMapping("/list")
    public TableDataInfo list(TbPremisesInfo tbPremisesInfo)
    {
        startPage();
        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
        return getDataTable(list);
    }

    /**
     * 导出楼盘信息列表
     */
    @RequiresPermissions("haoniu-premises:info:export")
    @Log(title = "楼盘信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPremisesInfo tbPremisesInfo)
    {
        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
        ExcelUtil<TbPremisesInfo> util = new ExcelUtil<TbPremisesInfo>(TbPremisesInfo.class);
        util.exportExcel(response, list, "楼盘信息数据");
    }

    /**
     * 获取楼盘信息详细信息
     */
    @RequiresPermissions("haoniu-premises:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbPremisesInfoService.selectTbPremisesInfoById(id));
    }

    /**
     * 新增楼盘信息
     */
    @RequiresPermissions("haoniu-premises:info:add")
    @Log(title = "楼盘信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPremisesInfo tbPremisesInfo)
    {
        return toAjax(tbPremisesInfoService.insertTbPremisesInfo(tbPremisesInfo));
    }

    /**
     * 修改楼盘信息
     */
    @RequiresPermissions("haoniu-premises:info:edit")
    @Log(title = "楼盘信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPremisesInfo tbPremisesInfo)
    {
        return toAjax(tbPremisesInfoService.updateTbPremisesInfo(tbPremisesInfo));
    }

    /**
     * 删除楼盘信息
     */
    @RequiresPermissions("haoniu-premises:info:remove")
    @Log(title = "楼盘信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbPremisesInfoService.deleteTbPremisesInfoByIds(ids));
    }
}
